<?php

namespace app\modules\admin\controllers;

use yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use app\modules\admin\components\BaseAdminController;
use app\components\Loyalty;

/**
 * Default controller for the `admin` module
 */
class CampaignController extends BaseAdminController
{
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'allow' => true,
                        'actions' => ['index'],
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'logout' => ['post'],
                ],
            ],
        ];
    }

    public function actionIndex()
    {
        $campaigns = $this->getCampaignList();
        return $this->render('index', [
            'campaigns' => $campaigns,
        ]);
    }

    // 创建一个新的Campaign
    private function createNewCampaign()
    {
        $data = [
            'campaign_type' => 'points',
            'campaign_name' => 'winshare',
            'points_ratio' => '1',
        ];

        return Loyalty::campaign_new($data);
    }

    // 获取Campaign列表
    private function getCampaignList()
    {
        return Loyalty::campaign_list();
    }
}
